<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>回调函数形式的ref</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
</head>

<body>

    <div id="react"> </div>
    <!--准备好一个容器-->
    <div id="test"></div>
    <!--引入react核心库,核心库必须先引入-->
    <script type="text/javascript" src="./js/react.development.js"></script>
    <!--引入react-dom, 用于支持react操作DOM-->
    <script type="text/javascript" src="./js/react-dom.development.js"></script>
    <!--引入babel,用于将jsx转为js-->
    <script type="text/javascript" src="./js/babel.min.js"></script>

    <!-- 引入prop-types，用于对组件标签属性进行限制 -->
    <script type="text/javascript" src="./js/prop-types.js"></script>

    <script type="text/babel">
        //定义组件
        class Wcomponent extends React.Component{
           //自定义赋值函数
           getDisplay=(()=>{
           console.log(this)
           alert(this.input1.value)
           })

          getDisplayTwo=(()=>{
           console.log(this)
           alert(this.input2.value)
           })

           // ref里面的回调函数是react调用的,返回的a是当前节点本身，this.input1 =a的意思是把当前拿到的真实DOM节点a，赋值给实例对象input1
           //console.log(this),就可以看到实例对象身上有input1
           
            render() {
                return(
                    <div>
                        <input ref={(a)=>{return this.input1 =a}} type="text" className="spacing"/>
                        {/*简写：<input ref={a=>this.input1 =a} type="text" className="spacing"/> */}
                        <button onClick={this.getDisplay}>点击</button> 
                     <input ref={(a)=>{return this.input2 =a}} onBlur={this.getDisplayTwo}  type="text" className="spacing"/>
                    </div>
                )  
            }
        }
        //渲染组件
        ReactDOM.render(<Wcomponent/>,document.getElementById("react"))


    </script>
    <style>
        .spacing {
            margin: 15px;
        }
    </style>

</body>

</html>